import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/LogionStudentServlet")
public class LogionStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取用户
        String username = req.getParameter("username");
        req.getParameter("password");
        //2.判断
        if(username==null || "".equals(username)){
            //2.1用户名为空 重定向登录页面
            resp.sendRedirect("/stu/login.jsp");
            return;
        }
        //2.2用户不为空  存入会话域中
        req.getSession().setAttribute("username",username);
        //3.重定向首页
        resp.sendRedirect("/stu/index.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
